import React,{PureComponent} from 'react';
import {connect} from 'react-redux';
import {LeftBarWrapper} from '../style';
import { Menu, } from 'antd';
import {NavLink} from "react-router-dom";

const SubMenu = Menu.SubMenu;


class LeftBar extends PureComponent {
    handleClick = (e) => {
        console.log('click ', e);
    };

    render(){
        const bar=this.props.checked;

        return(

            <LeftBarWrapper>

                {bar!=null? <Menu
                    onClick={this.handleClick}
                    style={{ width:280,float:'right', border: '10px solid #e1ebf4'}}
                    defaultOpenKeys={['1']}
                    mode="inline"
                >
                    <SubMenu key='1' title={<span style={{fontSize:'26px',color:'#0D6fB8',padding:'0 46px'}}>{bar.barType}</span>}>
                        {bar.menu.map((menu)=><Menu.Item  key={menu.id} className='secondLevel' style={{fontSize:'22px',margin:'0',height:'50px',lineHeight:'50px',}}>

                            {menu.menuPath=== '/ListPage' ? <NavLink className='secondLevel'  replace to={{pathname: menu.menuPath, state: {url: menu.menuUrl,bar:bar}}}>{menu.menuValue}</NavLink> :
                                menu.menuPath === '/HtmlPage' ? <p className='secondLevel' onClick={()=>{window.open(window.barIp+menu.menuPath+menu.menuUrl)}} >{menu.menuValue}</p>:
                                    <p className='secondLevel' onClick={()=>{window.open(menu.menuPath)}}>{menu.menuValue}</p>}
                        </Menu.Item>)}
                    </SubMenu>
                </Menu>:null}


            </LeftBarWrapper>
        )
    }
    componentWillUnmount() {

    }

}
const mapState=(state)=>({
    barMenu: state.getIn(['header','barMenu'])
});
const mapDispatch=(dispatch)=>({

});

export  default connect(mapState,mapDispatch)(LeftBar);